<?php

defined('MYLITS') ? '' : exit('No direct script access allowed');

/**
 * @version     1.0.0
 * @package     mylits engine
 * @license     GNU General Public License version 3
 * @author      Arfan Fudyartanto D N <arfan@mylits.com> - http://engine.mylits.com
 */
class Mylits_Language {

    private static $instance;
    private static $langCode;

    private function __construct() {
        
    }

    /**
     * This method will return Mylits_Language object
     * 
     * @return object Mylits_Language
     */
    public static function getInstance() {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Method to initial Mylits_Language
     */
    public static function init() {
        if (Mylits_System::getRequest('lang')) {
            self::$langCode = Mylits_System::getRequest('lang');
            $_SESSION['lang'] = self::$langCode;
        } else if (isset($_SESSION['lang'])) {
            self::$langCode = $_SESSION['lang'];
        } else {
            self::$langCode = Mylits_Config::getValue('default_language');
        }
    }

    /**
     * Method to get tranlation text
     * 
     * @param string $langCode -> country code (standart ISO 639-1)
     * @return string -> translation value
     */
    public static function getText($langTextCode) {
        if (Mylits_Config::issetParam('db')) {
            $model = Mylits_Loader::getModel('language', ENGINE_DIR . '/core/models/language.mdls.php');
            $translations = $model->getText($langTextCode, self::$langCode);
        }else{
            $translations = '[' . $langTextCode .']';
        }
        return $translations;
    }

    /**
     * Method to get active lang code 
     * 
     * @return string languge code (standart ISO 639-1)
     */
    public static function getLangCode() {
        return self::$langCode;
    }

}

?>
